﻿<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="WebConfigRoleProvider.Web._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title></title>
</head>
<body>
  <form id="form1" runat="server">
  <div>
    <h1>
      Web.config role provider</h1>
    <p>
      &nbsp;Store roles in web.config. Convenient for smaller web applications, role management
      on development setups or other scenarios where it&#39;s not possible/practical to
      use the SQL Server Role Provider.</p>
    <h2>
      Features</h2>
    <ul>
      <li>Roles stored in web.config. Fast to set up, easy to deploy.</li>
      <li>Supports external configuration files.</li>
      <li>Intellisense in Visual Studio with included schema.</li>
      <li>HttpHandler for assigning users to roles (and be used with other role providers
        as well).</li>
      <li>Can easily be extended with other storage mediums such as plain xml or databases.</li>
    </ul>
    <h2>
      Configuration</h2>
    <ol>
      <li>Copy the dll to the bin directory or your app.</li>
      <li>Add this element to the config tag in web.config:&nbsp; &lt;section name="WebConfigRoleProvider"
        type="WebConfigRoleProvider.Core.ConfigurationSection"/&gt; </li>
      <li>Set the role provider for you app in configuration -&gt; system.web:
        <br />
        &lt;configuration&gt;<br />
        ...<br />
        &lt;roleManager enabled=&quot;true&quot; defaultProvider=&quot;WebConfigRoleProvider&quot;&gt;
        <br />
        &nbsp; &lt;providers&gt;
        <br />
        &nbsp;&nbsp;&nbsp; &lt;add name=&quot;WebConfigRoleProvider&quot; type=&quot;WebConfigRoleProvider.Core.WebConfigRoleProvider&quot;/&gt;
        <br />
        &nbsp; &lt;/providers&gt;
        <br />
        &lt;/roleManager&gt;<br />
        ...<br />
        &lt;/configuration&gt;</li>
      <li>Configure roles in web.config in the configuration tag:
        <br />
        &lt;configuration&gt;br /> ...<br />
        &lt;WebConfigRoleProvider&gt;
        <br />
        &nbsp; &lt;roles&gt;
        <br />
        &nbsp;&nbsp;&nbsp; &lt;add name=&quot;role1&quot; users=&quot;user1, user2, user3,
        xxx&quot; /&gt;
        <br />
        &nbsp;&nbsp;&nbsp; &lt;add name=&quot;role2&quot; users=&quot;user1, user3&quot;
        /&gt;
        <br />
        &nbsp; &lt;/roles&gt;
        <br />
        &lt;/WebConfigRoleProvider&gt;
        <br />
        ...<br />
        &lt;/configuration&gt;</li>
    </ol>
    <h3>
      Setting up users in web.config</h3>
    <p>
      Both users managed with the Membership provider and users hardcoded into web.config
      are supported.
    </p>
    <h3>
      Using the HttpHandler</h3>
    <p>
      Add this tag to the configuration -&gt; sytstem.web -&gt; HttpHandlers section in
      web.config:</p>
    <p>
      &lt;add verb=&quot;GET&quot; path=&quot;usersroles.ashx&quot; type=&quot;WebConfigRoleProvider.Core.UsersRolesMatrixHttpHandler&quot;/&gt;</p>
    <p>
      Load the page in a browser, <a href="http://yoursite/usersroles.ashx">http://yoursite/usersroles.ashx</a>.</p>
    <p>
      IMPORTANT: Disable the HttpHandler when deploying to a live environment, or at least
      require autentication to access it.</p>
    <h3>
      Enabling Intellisense</h3>
    <p>
      Save the WebConfigRoleProvider.xsd schema somewhere on your workstation. VS2008
      keeps its schemas in C:\Program Files\Microsoft Visual Studio 9.0\Xml\Schemas\,
      you could use the same location. Open your web.config and see the properties. Click
      the elipsis for the &quot;Schemas&quot; property and select the schema.</p>
    <h3>
      Using an external config file</h3>
    <p>
      Like most other elements in web.config, you can chose to keep the roles in a separate
      config file to reduce the clutter in web.config.</p>
    <p>
      Add a configSource attribute the WebConfigRoleProvider element in web.config:</p>
    <p>
      &lt;WebConfigRoleProvider configSource=&quot;roles.config&quot;&gt;</p>
    <p>
      The content of the config file follows the same syntax, and you can also enable
      the same intellisense with the schema.</p>
    <p>
      Sample:
    </p>
    <p>
      &lt;?xml version=&quot;1.0&quot;?&gt;
      <br />
      &lt;WebConfigRoleProvider&gt;
      <br />
      &nbsp; &lt;roles&gt;
      <br />
      &nbsp;&nbsp;&nbsp; &lt;add name=&quot;role1&quot; users=&quot;user1, user2, user3,
      xxx&quot; /&gt;
      <br />
      &nbsp;&nbsp; &lt;add name=&quot;role2&quot; users=&quot;user2, user3&quot; /&gt;
      <br />
      &nbsp; &lt;/roles&gt;
      <br />
      &lt;/WebConfigRoleProvider&gt;
    </p>
  </div>
  </form>
  <h2>
    Background and some interesting notes on the project</h2>
  <p>
    I often found myself in situations where using the SQL Server RoleProvider seemed
    like overkill. And I always thought it was a bit peculiar you could set up users
    for the website in web.config, but there was no &quot;out-of-the-box&quot; way to
    use Roles.</p>
  <p>
    It&#39;s especially convenient for scenarios where you just want to get up and running
    quickly. Once the app reaches live deployment, the Role provider can be replaced
    with a SQL Server version or similar &quot;production grade&quot; provider. </p>
  <p>
    This iRoleProvider implementation follows the guidelines found on MSDN: <a href="http://msdn.microsoft.com/en-us/library/8fw7xh74.aspx">
      http://msdn.microsoft.com/en-us/library/8fw7xh74.aspx.</a>
  </p>
  <h3>
    The HttpHandler</h3>
  <p>
    The HttpHandler started out as simple way to do testing, but eventually turned into
    a nice little utility to manage users and roles. You may find it even more practical
    to use than the standard ASP.NET Configuration pages.
  </p>
  <p>
    It uses an included resource, the UsersRolesMatrixTemplate.htm file, which contains
    two &quot;placeholders&quot;. If you modify the template, please note your changes
    are only available after the project has been recompiled.</p>
  <p>
    It also uses jQuery (hosted on the Microsoft.com CDN) and the HTML generated is
    very lean and basic. It&#39;s amazing what kind of functionality you can achieve
    with a few lines of jQuery magic... Check it out, it&#39;s pretty neat.</p>
</body>
</html>
